#include "dpm_config.h"
#include <QCoreApplication>
#include <QSettings>


DPM_Config::DPM_Config(QObject *parent) : QObject(parent)
{
    this->readConfig();
}
void DPM_Config::readConfig(){
    QString  m_qstrFileName = QCoreApplication::applicationDirPath() + "/config/MinddlewareConfig.ini";
    QSettings * m_psetting = new QSettings(m_qstrFileName, QSettings::IniFormat);
    m_psetting->setIniCodec("UTF-8");

    QVariant qvar = m_psetting->value(QString("/%1/%2").arg("INFO").arg("dir"));
    this->dir=qvar.toString();

    QVariant qtitle = m_psetting->value(QString("/%1/%2").arg("INFO").arg("title"));
    this->title =qtitle.toString();

    QVariant baddir = m_psetting->value(QString("/%1/%2").arg("INFO").arg("baddir"));
    this->batDir=baddir.toString();

    QVariant vgroup = m_psetting->value(QString("/%1/%2").arg("INFO").arg("group"));
    this->group=vgroup.toString();

    QVariant vid = m_psetting->value(QString("/%1/%2").arg("INFO").arg("appid"));
    this->appid=vid.toString();

    QVariant vitem = m_psetting->value(QString("/%1/%2").arg("INFO").arg("item"));
    this->item=vitem.toString();

    QVariant vip = m_psetting->value(QString("/%1/%2").arg("INFO").arg("ip"));
    this->serverip=vip.toString();

    QVariant vport = m_psetting->value(QString("/%1/%2").arg("INFO").arg("port"));
    this->serverport=vport.toInt();

    QVariant vrelink = m_psetting->value(QString("/%1/%2").arg("INFO").arg("relink"));
    this->relink=vrelink.toInt();

    QVariant vlobby = m_psetting->value(QString("/%1/%2").arg("INFO").arg("lobby"));
    this->lobby=vlobby.toString();
    QVariant vroom = m_psetting->value(QString("/%1/%2").arg("INFO").arg("room"));
    this->room =vroom.toString();
    QVariant vuser = m_psetting->value(QString("/%1/%2").arg("INFO").arg("user"));
    this->user=vuser.toString();



}
void DPM_Config::writeConfig(){
    QString  m_qstrFileName = QCoreApplication::applicationDirPath() + "/config/MinddlewareConfig.ini";
    QSettings * m_psetting = new QSettings(m_qstrFileName, QSettings::IniFormat);
    m_psetting->setIniCodec("UTF-8");

    m_psetting->setValue(QString("/%1/%2").arg("INFO").arg("dir"),this->dir);

    m_psetting->setValue(QString("/%1/%2").arg("INFO").arg("title"),this->title);


    m_psetting->setValue(QString("/%1/%2").arg("INFO").arg("baddir"),this->batDir);


    m_psetting->setValue(QString("/%1/%2").arg("INFO").arg("group"),group);


    m_psetting->setValue(QString("/%1/%2").arg("INFO").arg("appid"),this->appid);


    m_psetting->setValue(QString("/%1/%2").arg("INFO").arg("item"),this->item);


    m_psetting->setValue(QString("/%1/%2").arg("INFO").arg("ip"),this->serverip);


    m_psetting->setValue(QString("/%1/%2").arg("INFO").arg("port"),this->serverport);


    m_psetting->setValue(QString("/%1/%2").arg("INFO").arg("relink"),this->relink);


}

void DPM_Config::save(){
    writeConfig();
    emit valuechang();
}
